import Request from 'luch-request'

const serve = new Request();
const appKey = 'wEZMPRkpdKLcaEKpTc03Ujzu';
const appSecret = 'smKWyCiSvaYFVYRaouz2bLq6aIPWs3cM';

serve.setConfig((config) => { /* config 为默认全局配置*/
	config.baseURL = 'https://openapi.baidu.com/oauth/2.0'; /* 根域名 */
	config.header = {
		'content-type': 'application/x-www-form-urlencoded'
	};
	timeout: 5000
	return config
})

export function getBaiduToken() {
	return serve.request({
		url: `/token?grant_type=client_credentials&client_id=${appKey}&client_secret=${appSecret}`,
		method: 'get',
		timeout: 5000
	})
}

serve.setConfig((config) => { /* config 为默认全局配置*/
	config.baseURL = 'http://tsn.baidu.com'; /* 根域名 */
	config.header = {
		'content-type': 'application/x-www-form-urlencoded'
	};
	timeout: 5000
	return config
})

export function getSpeechByText(data){
	return serve.request({
		url:'/text2audio',
		method: 'post',
		data
	})
}
